package tech.aistar.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import tech.aistar.entity.Intention;
import tech.aistar.entity.Tenant;
import tech.aistar.service.IIntentionService;
import tech.aistar.service.ITenantService;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/intention")
public class IntentionController {
    @Autowired
    private IIntentionService intentionService;
    @Autowired
    private ITenantService tenantService;


    @GetMapping("/TenantIntention")
    public String selectAll(HttpServletRequest request) {
        String tenantId = request.getParameter("tenantId");
        Intention intention = intentionService.selectById(Integer.valueOf(tenantId));
        request.setAttribute("intention", intention);
        Tenant tenant = tenantService.selectById(Integer.valueOf(tenantId));
        request.setAttribute("tenant", tenant);

        return "/personal_homepage/tenant/intention";

    }

    @GetMapping("/updateIntention")
    public String updateIntention(HttpServletRequest request) {
        String fridge = request.getParameter("fridge");
        String television = request.getParameter("television");
        String airCondition = request.getParameter("airCondition");
        String geyser = request.getParameter("geyser");
        String washingMachine = request.getParameter("washingMachine");
        String broadband = request.getParameter("broadband");
        String sofa = request.getParameter("sofa");
        String balcony = request.getParameter("balcony");
        String gasStove = request.getParameter("gasStove");
        String rangeHood = request.getParameter("rangeHood");
        String wardrobe = request.getParameter("wardrobe");
        String heat = request.getParameter("heat");
        String bed = request.getParameter("bed");
        String intelligentLock = request.getParameter("intelligentLock");
        String greenery = request.getParameter("greenery");
        String schoolNearbyHouse = request.getParameter("schoolNearbyHouse");
        String cookingable = request.getParameter("cookingable");
        String bathroom = request.getParameter("bathroom");
        String trafficConvenient = request.getParameter("trafficConvenient");
        String shoppingConvenient = request.getParameter("shoppingConvenient");
        String tenantId = request.getParameter("tenantId");

        Intention intention = new Intention(Integer.valueOf(tenantId),
                greenery,
                trafficConvenient,
                shoppingConvenient,
                schoolNearbyHouse,
                fridge,
                television,
                washingMachine,
                geyser,
                airCondition,
                broadband,
                sofa,
                bed,heat,wardrobe,cookingable,bathroom,balcony,intelligentLock,rangeHood,gasStove);

        int count = intentionService.updateByTenantId(intention);

        return "forward:/intention/TenantIntention.action?";
    }





    @GetMapping("/TenantDemand")
    public String selectAllDemand(HttpServletRequest request) {
        String tenantId = request.getParameter("tenantId");
        Intention intention = intentionService.selectById(Integer.valueOf(tenantId));
        request.setAttribute("intention", intention);
        Tenant tenant = tenantService.selectById(Integer.valueOf(tenantId));
        request.setAttribute("tenant", tenant);

        return "/personal_homepage/tenant/demand";
    }


    @GetMapping("/updateDemand")
    public String updateDemand(HttpServletRequest request) {
        String houseType = request.getParameter("houseType");
        String floor = request.getParameter("floor");
        String parkPlace = request.getParameter("parkPlace");
        String orientate = request.getParameter("orientate");
        String tenantId = request.getParameter("tenantId");

        Intention intention = new Intention(Integer.valueOf(tenantId),houseType,Integer.valueOf(floor),parkPlace,orientate);

        int count = intentionService.updateDemandByTenantId(intention);

        return "forward:/intention/TenantDemand.action";
    }


}
